package com.xjrsoft.module.customerTwo.EMP.repair.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xjrsoft.common.page.PageOutput;
import com.xjrsoft.common.page.ConventPage;
import java.util.List;
import com.xjrsoft.common.utils.DataTransUtil;
import com.xjrsoft.common.result.Response;
import com.xjrsoft.core.tool.utils.BeanUtil;
import com.xjrsoft.module.customerTwo.EMP.repair.dto.TElectricRepairDto;
import com.xjrsoft.module.customerTwo.EMP.repair.dto.SaveTElectricRepairFormDataDto;
import com.xjrsoft.module.customerTwo.EMP.repair.vo.TElectricRepairVo;
import com.xjrsoft.module.customerTwo.EMP.repair.vo.TElectricRepairListVo;
import com.xjrsoft.module.customerTwo.EMP.repair.dto.TElectricRepairListDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;

import org.springframework.web.bind.annotation.*;
import com.xjrsoft.module.customerTwo.EMP.repair.entity.TElectricRepair;
import com.xjrsoft.module.customerTwo.EMP.repair.vo.TElectricRepairVo;
import com.xjrsoft.module.customerTwo.EMP.repair.service.ITElectricRepairService;

/**
 *  控制器
 *
 * @author lisen
 * @since 2023-08-04
 */
@RestController
@AllArgsConstructor
@RequestMapping("/repair")
@Api(value = "维修赔偿", tags = "维修赔偿接口")
public class TElectricRepairController {


	private final ITElectricRepairService tElectricRepairService;


	/**
	 * 详情 
	 */
	@GetMapping("/{id}")
	@ApiOperation(value = "详情", notes = "传入id")
	@SaCheckPermission(value = {"repair:view", "repair:modify"}, mode = SaMode.OR)
	public Response<TElectricRepairVo> getFormData(@PathVariable String id) {
		// 主表数据
		TElectricRepair tElectricRepair = tElectricRepairService.getById(id);
		TElectricRepairVo tElectricRepairVo = BeanUtil.copy(tElectricRepair, TElectricRepairVo.class);
		return Response.ok(tElectricRepairVo);
	}

	/**
	 * 自定义分页 
	 */
	@GetMapping
	@ApiOperation(value = "分页", notes = "传入tElectricRepair")
		public Response<PageOutput<TElectricRepairListVo>> getPageList(TElectricRepairListDto listDto) {
		IPage<TElectricRepair> page = tElectricRepairService.getPageList(listDto);
		List<TElectricRepairListVo> records = BeanUtil.copyList(page.getRecords(), TElectricRepairListVo.class);
			// 转换列表数据
		DataTransUtil.transListShowData(records);
		return Response.ok(ConventPage.getPageOutput(page.getTotal(), records));
	}

	/**
	 * 新增 
	 */
	@PostMapping
	@ApiOperation(value = "新增", notes = "传入tElectricRepair")
	@SaCheckPermission("repair:add")
	public Response save(@RequestBody SaveTElectricRepairFormDataDto formDto) {
		TElectricRepairDto tElectricRepairDto = formDto.getTElectricRepairDto();
		TElectricRepair tElectricRepair = BeanUtil.copy(tElectricRepairDto, TElectricRepair.class);
		boolean isSuccess = tElectricRepairService.addTElectricRepair(tElectricRepair);
		return Response.status(isSuccess);
	}

	/**
	 * 修改 
	 */
	@PutMapping("/{id}")
	@ApiOperation(value = "修改", notes = "传入tElectricRepair")
	@SaCheckPermission("repair:modify")
	public Response update(@PathVariable String id, @RequestBody SaveTElectricRepairFormDataDto formDto) {
		TElectricRepairDto tElectricRepairDto = formDto.getTElectricRepairDto();
		TElectricRepair tElectricRepair = BeanUtil.copy(tElectricRepairDto, TElectricRepair.class);
		return Response.status(tElectricRepairService.updateTElectricRepair(id, tElectricRepair));
	}



	/**
	 * 删除 
	 */
	@DeleteMapping("/{ids}")
	@ApiOperation(value = "删除", notes = "传入ids")
	@SaCheckPermission(value = {"repair:batchDelete", "repair:delete"}, mode = SaMode.OR)
	public Response remove(@ApiParam(value = "主键集合", required = true) @PathVariable String ids) {
		return Response.status(tElectricRepairService.delete(ids));
	}

	@PostMapping("/confirm/{id}")
	@ApiOperation(value = "确认", notes = "传入id")
	@SaCheckPermission("repair:lock")
	public Response confirm(@PathVariable String id) {
		return Response.status(tElectricRepairService.confirm(id));
	}

	@GetMapping("/getListByRoomNum/{num}")
	@ApiOperation(value = "获得List<维修单信息>", notes = "传入房间号码")
	@SaCheckPermission(value = {"repair:view", "repair:modify"}, mode = SaMode.OR)
	public Response repairList(@PathVariable String num) {
		return Response.ok(tElectricRepairService.getByRoomNumber(num));
	}
}
